﻿<!doctype html>
<html>
<head>
    <title>微街秀 > 支付订单</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <link href="plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="css/css.css">
    <script src="js/ajax-data.js" type="text/javascript"></script>
    <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="js/base.js" type="text/javascript"></script>
    <script src="js/dialog.js" type="text/javascript"></script>   
    <style type="text/css">
        .seltag{width: 100%;border-bottom: 1px #ccc solid;background: white;height: 70px;}
        .floatLeft{float: left; margin-left: 20px;color: #414141;line-height: 20px;}
        .floatRight{ float: right; margin: 25px 30px 0 0;}
        .selecttag{border:1px #F37B0B solid; color: white;width: 20px;height: 20px;border-radius: 20px;line-height: 20px;text-align: center; }
        #sum{ font-size: 18px;}
        .submit{width: 95%; margin: 20% auto 0 auto; line-height: 40px; height: 40px; color: white; text-align: center; background-color: #F37B0B; border-radius: 10px;font-size: 16px; }
        #sum{color:#fff;}
    </style>
</head>
<body>
    <div>
        <div class="wamtop">
            <div class="topleft goback">
                <img src="img/5.jpg" /></div>
            <div class="topcententxt title">
                确认支付
            </div>
        </div>
        <div class="tg_select">
            <div class="seltag">
                <div class="floatLeft">
                    <p style="font-size: 16px; font-weight: 900; margin-top: 15px;">
                        使用余额支付<span class="sys_price">0</span>元</p>
                    <p style="font-size: 12px; color: #ccc">
                        账户余额：<a class="balance">0</a> 元</p>
                </div>
                <div class="floatRight">
                    <div id="0" class="selecttag balan">&#10003;</div>
                </div>
            </div>
            <div class="seltag">
                <div class="floatLeft">
                    <div style="font-size: 16px; font-weight: 900; margin-top: 15px; width: 145px;">
                        支付宝支付
                        <div style="float: right; font-size: 14px; border: 1px #F37B0B solid; height: 18px;width: 50px; line-height: 20px; text-align: center; color: #F37B0B;">
                            推荐</div>
                    </div>
                    <p style="font-size: 12px; color: #ccc">
                        推荐有支付宝账号的用户使用</p>
                </div>
                <div class="floatRight">
                    <div id="2" class="selecttag Other">&#10003;</div>
                </div>
            </div>
            <div class="seltag" style="display: none;">
                <div class="floatLeft">
                    <p style="font-size: 16px; font-weight: 900; margin-top: 15px;">
                        微信支付</p>
                    <p style="font-size: 12px; color: #ccc">
                        建议安装微信5.0版本以上使用</p>
                </div>
                <div class="floatRight">
                    <div id="1" class="selecttag Other">&#10003;</div>
                </div>
            </div>
            <div class="submit">
                <span>立即付款</span></span> <a id="sum">￥<span class="pay_price">0</span>元</a>
            </div>
        </div>
    </div>


           <div class="backimg-panl buzhou hide">
        <div class="font-content" style="top: 40%;">
            <img src="img/buzhou/3_13.png" />
            <div class=" text-center" style="margin-top: -40px;">
                <p>
                   点击立即付款</p>
          
                <p>
                    <button class=" btn btn-color btn-default " onclick="NextBZ(1)">
                        下一步</button></p>
            </div>
        </div>
    </div>

        <div class="backimg-panl buzhou hide">
        <div class="font-content" style="top: 35%;">
            <img src="img/buzhou/3_12.png" />
            <div class=" text-center" style="margin-top: -40px;">
                <p>
                    支付成功后，</p>
                <p>
                    即广告文章已分享成功
                </p>
                <p>
                    <button class=" btn btn-color btn-default " onclick="SetBZ(34)">
                        知道了</button></p>
            </div>
        </div>
    </div>

    <script>
        ShowBZ(34); //显示引导
        var id = 0, balance = 0;
        var unit_price, total_price = 0, pay_price, number, platform, state;

        $(document).ready(function () {

            $(".goback").bind("click", GoBack);
            $(".balan").click(function () {
                $(this).removeClass("sys");
                if ($(this).css("background-color").indexOf("243") > -1)
                    $(this).css("background-color", "white");
                else {
                    $(this).addClass("sys");    //选中状态
                    $(this).css("background-color", "#F37B0B");
                }
                setPlatform(this.id);
            });

            $(".Other").click(function () {
                $(".Other").css("background-color", "");
                $(this).css("background-color", "#F37B0B");
                $(".Other").removeClass("pay");
                $(this).addClass("pay");    //选中状态
                setPlatform(this.id);
            });
            load(1);
        });

        function load(page) {
            if (!islogin()) { window.location.href = 'login.html'; return; }
            id = getQueryString("id");
            AjaxStart("ajax/fc_article.ashx?getsetting", "id=" + id, function (data) {
                loadhtml(data.item);
            });
        }

        function loadhtml(item) {
            $(".op_total").html(item["op_total"]);
            $(".op_price").html(item["op_price"]);
            state = item["state"];

            if (item["op_price"] == null || item["op_total"] == null || isNaN(item["op_price"]) || isNaN(item["op_total"])) {
                Alert('请先设置价格');
                setTimeout(function () { window.location.href = 'makeset.html?id=' + id }, 1000);
                return;
            }

            unit_price = parseFloat(item["op_price"]);  //单价
            number = parseFloat(item["op_total"]);      //数量
            total_price = parseFloat(unit_price * number).toFixed(2);  //订单总额  
            loadBalance();      //余额
        }

        //显示余额
        function loadBalance() {
            balance = 0;
            AjaxStart("ajax/user.ashx?getbalance&rand=" + Math.random(), "type=1", function (json) {
                if (json.code == 0) {
                    balance = parseFloat(json.item).toFixed(2);
                    $(".submit").bind("click", AddOrder);   //提交事件
                }
                else
                    Alert(json.msg);
                $(".Other").eq(0).click();  //默认方式支付
            });
        }

        //设置支付方式
        function setPlatform(type) {
            platform = type;            //支付方式
            pay_price = total_price;    //在线支付金额
            $(".sys_price").html("0");  //余额支付金额
            $(".balance").html(parseFloat(balance))
            balance = parseFloat(balance);
            total_price = parseFloat(total_price);

            if (balance >= total_price) {
                //在线支付
                if (type > 0) {
                    $(".balan").removeClass("sys");
                    $(".balan").removeAttr("style");
                }
                //余额支付(余额 >= 支付金额)
                if (document.getElementById("0").className.indexOf("sys") > -1) {
                    $(".Other").removeClass("pay");
                    $(".Other").removeAttr("style");
                    pay_price = 0;                      //余额全付,不用在线充值 
                    $(".sys_price").html(total_price);
                    $(".balance").html(parseFloat(balance - total_price).toFixed(2))
                }
            }
            else {
                //余额支付 (余额 < 支付金额)
                if (document.getElementById("0").className.indexOf("sys") > -1) {
                    pay_price = total_price - balance;   //在线充值
                    $(".sys_price").html(parseFloat(balance));
                }
                platform = $(".pay").attr("id");    //余额不足，换其他支付方式
            }

            if (pay_price > total_price)
                pay_price = total_price;
            $(".pay_price").html(parseFloat(parseFloat(total_price).toFixed(2)));
        }

        var isSend = false;
        function AddOrder() {
            var article_id = getQueryString("id");
            var pay_price = GetMoney();
            var sys_price = $(".sys_price").html();
            if (state > 0) {
                Alert("此广告已交易");
                return;
            }

            if (isSend) {
                Alert("正在提交..");
                return;
            }
//            if (navigator.userAgent.indexOf("wjx") == -1) {
//                Alert("请使用客户端APP");
//                return;
//            }
            var param = "article_id=" + article_id + "&total_price=" + total_price + "&pay_price=" + pay_price + "&sys_price=" + sys_price + "&unit_price=" + unit_price + "&number=" + number + "&platform=" + platform;

            //余额支付
            if (balance >= total_price && document.getElementById("0").className.indexOf("sys") > -1) {
                isSend = true;
                AjaxStart("ajax/fc_order.ashx?sysaddorder&rand=" + Math.random(), param, function (json) {
                    isSend = false;
                    if (json.code == 0)
                        payCallback();
                    else
                        Alert(json.msg);

                });
            }
            else {
                //在线支付        
                AjaxStart("ajax/fc_order.ashx?addorder&rand=" + Math.random(), param, function (json) {
                    if (json.code == 0)
                        GoPay(platform, json.item);
                    else
                        Alert(json.msg);
                });
            }
        }

        function GoPay(platform, item) {
            //微信支付
            if (platform == 1) {
                var param = { subject: "微街秀广告支付", body: $(".title").html(), money: parseFloat(GetWXMoney()), outTradeNo: item.orderid, notifyUrl: "http://wjxtest.711688.com/client/api/wx_notify.aspx", callback: "payCallback" };
                window.location.href = "callback://weixinPay?" + JSON.stringify(param);
            }
            else if (platform == 2) {
                var param = { "subject": "微街秀广告支付", "body": $(".title").html(), "price": GetMoney(), "out_trade_no": item.orderid, "notify_url": item.notify_url, "callback": "payCallback" };
                window.location.href = "callback://alipay?" + JSON.stringify(param);
            }
        }

        function payCallback() { window.location.href = "makeoutcome.html"; }

        function GetMoney() {
            return parseFloat(pay_price).toFixed(2).toString();   //最小单位：元
        }

        function GetWXMoney() {
            var money = parseFloat(pay_price) * 100;  //最小单位：分
            return money.toFixed(2);
        }

        function GoBack() { window.location.href = 'MakeFX.html?id=' + id; }
    </script>
</body>
</html>
